<%@ page import="ee.ttu.rakarh.model.data.entities.ItemAttribute" %>
<%@page import="ee.ttu.rakarh.model.data.DataType"%>
<jsp:useBean id="item" scope="request" type="ee.ttu.rakarh.model.data.entities.Item" />

    <script type="text/javascript" src="js/addItem.js"></script>
    
	<form id="updateItemForm" method="post" action="/ladu/api?a=updateItem&itemId=<%= item.getId() %>">
	<div style="white-space:nowrap;">
		<div class="inlineFormBlock" stype="width:200px;">
			<div><div class="requiredMark">*</div>Name:<br/><input name="name" type="text" value="<%= item.getName() %>"/></div><div class="errorDiv" id = "nameErrorDiv"></div>
			<div><div class="requiredMark">*</div>Sale price:<br/><input name="salePrice" type="text" value="<%= item.getSalePrice() %>"/></div><div class="errorDiv" id = "salePriceErrorDiv"></div>
			<div><div class="requiredMark">*</div>Producer:<br/><input name="producer" type="text" value="<%= item.getProducer() %>"/></div><div class="errorDiv" id = "producerErrorDiv"></div>
			<div><div class="requiredMark">*</div>Description:<br/><input name="description" type="text" value="<%= item.getDescription() %>"/></div><div class="errorDiv" id = "descriptionErrorDiv"></div>
			<div><div class="requiredMark">*</div>Producer code:<br/><input name="producerCode" type="text" value="<%= item.getProducerCode() %>"/></div>	<div class="errorDiv" id = "producerCodeErrorDiv"></div>	
		</div>
		<div class="inlineFormBlock" stype="width:200px;">
			<div id="form_attributes">
				<% 
				for(ItemAttribute itemAttribute : item.getItemAttributes()){
					out.println("<div>");
					
					
					String requiredMark = "";// itemAttribute.getItemAttributeType().getTypeAttribute().isRequired() ? "*" : "";
					String value = itemAttribute.getItemAttributeType().getDataType() == DataType.NUMBER ? itemAttribute.getValueNumber().toString() : itemAttribute.getValueText();
					out.println(itemAttribute.getItemAttributeType().getTypeName());
					out.println("<br/>");
					out.println("<div class=\"requiredMark\">" + requiredMark + "</div>");
					out.println("<input name=\"" + itemAttribute.getItemAttributeType().getId() + "\" type=\"text\" value=\"" + value +"\"/ >");
					out.println("</div>");
					out.println("<div class=\"errorDiv\" id = \""+ itemAttribute.getItemAttributeType().getId() +"ErrorDiv\"></div>");
					
				}
				%>
			</div>
		</div>
	</div>
		<div><button id="submit1" name="submitButton" >Update item</button></div>
	</form>
	<div id="successNotification">
		<p>Item is updated</p>
	</div>
	<div id="errorNotification">
		<p>Errors!</p>
	</div>